﻿using System;
using System.Data;
using System.Collections.Generic;
using ZHDJ.MobileInterface.Common;
using SXT.Party.Law.Model;

/*我的咨询*/

namespace ZHDJ.MobileInterface
{
    public partial class GetLawyerConsultation : AbstractBasePage
    {
        protected override OutParam BusinessProcess<InParam, OutParam>(InParam inParam)
        {
            // 业务逻辑返回的响应对象  
            LawyerConsultationOutParam result = new LawyerConsultationOutParam();
            LawyerConsultationInParam param = new LawyerConsultationInParam();
            string logMsg = "";
            bool isFlag = true;

            try
            {
                param = inParam as LawyerConsultationInParam;


                if (param.page_no * param.page_count <= 0)
                {
                    result.code = "0";
                    result.desc = "当前页,以及页记录条数必须为大于0的正整数";

                    isFlag = false;
                }

                //if(string.IsNullOrEmpty(param.LawyerID))
                //{
                //    result.code = "0";
                //    result.desc = "律师ID不能为空。";

                //    isFlag = false;
                //}

                if (isFlag)
                {
                    string LoginIDEX = "";
                    if (!string.IsNullOrEmpty(param.LoginID))
                    {
                        LoginIDEX = param.LoginID;
                    }
                    bool IsContinue = true;
                    //if (string.IsNullOrEmpty(param.LawyerID))
                    //{
                    //    IsContinue = false;
                    //}
                    int replyTypeEx = 0;
                    if (!string.IsNullOrEmpty(param.replyType))
                    { replyTypeEx = Convert.ToInt32(param.replyType); }

                    DataSet ds = PartyLawConsultation.GetGridDataPage(param.page_no, param.page_count, LoginIDEX, param.LawyerID, replyTypeEx, "MobileService");
                    if (ds != null && ds.Tables.Count == 2)
                    {
                        LawyerConsultationData itemTemp;

                        result.data.total_pages = CommonUtils.GetTotalPages(Convert.ToInt32(ds.Tables[1].Rows[0][0]), param.page_count);
                        if (IsContinue)
                        {
                            var Cou = PartyLawConsultationReply.LawyerReplyConsultationCount(param.LawyerID, "Mobile");
                            result.data.NotReplyed = (Cou[0] - Cou[1]).ToString();
                            result.data.Replyed = Cou[1].ToString();
                        }
                        foreach (DataRow dr in ds.Tables[0].Rows)
                        {
                            itemTemp = new LawyerConsultationData();
                            itemTemp.ConsultationID = dr["ConsultationID"].ToString();
                            itemTemp.Content = dr["Content"].ToString();
                            itemTemp.CreateTime = dr["CreateTime"].ToString();
                            itemTemp.LawyerName = dr["UserName"].ToString();
                            itemTemp.RegistrationNum = dr["RegistrationNum"].ToString();
                            itemTemp.LawFirmName = dr["LawFirmName"].ToString();
                            itemTemp.LawyerID = dr["Lawyer"].ToString();
                            if (IsContinue)
                            {
                                DataSet dsR = PartyLawConsultationReply.GetGridData(Convert.ToString(dr["ConsultationID"]), "Mobile");
                                if (dsR != null)
                                {
                                    foreach (DataRow drR in dsR.Tables[0].Rows)
                                    {
                                        LawyerConsultationR itemTempR;
                                        itemTempR = new LawyerConsultationR();
                                        itemTempR.ReplyID = drR["ReplyID"].ToString();
                                        itemTempR.ReplyByType = drR["ReplyByType"].ToString();
                                        itemTempR.Content = drR["Content"].ToString();
                                        itemTempR.CreateTime = drR["CreateTime"].ToString();
                                        itemTempR.ReplyBy = drR["ReplyBy"].ToString();
                                        itemTemp.list.Add(itemTempR);
                                    }
                                }
                            }
                            result.data.list.Add(itemTemp);
                        }

                    }
                }

                logMsg = result.desc;
            }
            catch (Exception ex)
            {
                result.code = "0";
                result.desc = "操作异常，多次出现请联系管理员";
                logMsg = ex.Message + ":" + ex.StackTrace;
            }

            CommonUtils.InsertMobileInterfaceLog(SystemCode + "-GetLawyerConsultation", SerializeHelper.JsonSerializer<LawyerConsultationInParam>(param), logMsg);
            return result as OutParam;
        }

        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (string.Compare(Request.QueryString["Safe"], "False", true) == 0)
                ProcessRequest<LawyerConsultationInParam, LawyerConsultationOutParam>();
            else
                SafeProcessRequest<LawyerConsultationInParam, LawyerConsultationOutParam>();
        }
    }

    #region 请求参数
    public class LawyerConsultationInParam
    {
        /// <summary>
        /// 必填 当前页
        /// </summary>
        public int page_no
        { get; set; }

        /// <summary>
        /// 必填，每页记录条数
        /// </summary>
        public int page_count
        { get; set; }

        /// <summary>
        /// 律师ID
        /// </summary>
        public string LawyerID
        { get; set; }

        public string LoginID
        { get; set; }

        public string replyType { get; set; }
    }
    #endregion


    #region 结果参数
    public class LawyerConsultationOutParam
    {
        public LawyerConsultationOutParam()
        {
            code = "1";
            desc = "操作成功";
            data = new LawyerConsultationList();
        }

        public string code
        { get; set; }

        public string desc
        { get; set; }

        public LawyerConsultationList data
        { get; set; }

    }

    public class LawyerConsultationList
    {
        public LawyerConsultationList()
        {
            total_pages = 0;
            list = new List<LawyerConsultationData>();
        }

        public List<LawyerConsultationData> list { get; set; }
        /// <summary>
        /// 总页数
        /// </summary>
        public int total_pages
        { get; set; }

        /// <summary>
        /// 已回复
        /// </summary>
        public string Replyed
        { get; set; }

        /// <summary>
        /// 已回复
        /// </summary>
        public string NotReplyed
        { get; set; }
    }

    public class LawyerConsultationData
    {
        public LawyerConsultationData()
        {

            list = new List<LawyerConsultationR>();
        }

        public List<LawyerConsultationR> list { get; set; }


        /// <summary>
        /// ConsultationID
        /// </summary>
        public string ConsultationID
        { get; set; }

        /// <summary>
        /// 内容
        /// </summary>
        public string Content
        { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public string CreateTime
        { get; set; }

        /// <summary>
        /// 律师ID
        /// </summary>
        public string LawyerID
        { get; set; }

        /// <summary>
        /// 律师名称
        /// </summary>
        public string LawyerName
        { get; set; }

        /// <summary>
        /// 执业编号
        /// </summary>
        public string RegistrationNum
        { get; set; }

        /// <summary>
        /// 律所名称
        /// </summary>
        public string LawFirmName
        { get; set; }



    }

    public class LawyerConsultationR
    {
        /// <summary>
        /// ID
        /// </summary>
        public string ReplyID
        { get; set; }

        /// <summary>
        /// 回复类型  1：回复  2：追问
        /// </summary>
        public string ReplyByType
        { get; set; }

        /// <summary>
        /// 内容
        /// </summary>
        public string Content
        { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public string CreateTime
        { get; set; }

        /// <summary>
        /// 回复人
        /// </summary>
        public string ReplyBy
        { get; set; }

    }
    #endregion
}